<template>
    <div class="charts">
        <div class="bar" ref="canvas"></div>
        <div class="bar" ref="canvas2"></div>
    </div>
</template>
   
<script setup>
import { ref, getCurrentInstance, onMounted } from 'vue';

const { proxy } = getCurrentInstance()

const canvas = ref() // dom实例
const canvas2 = ref() // dom实例
let myChart = null // echarts实例
let myChart2 = null // echarts实例

onMounted(() => {
    renderChart()
})

const renderChart = () => {
    myChart = proxy.$echarts.init(canvas.value)
    myChart2 = proxy.$echarts.init(canvas2.value)
    myChart.setOption({
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                data: [120, 200, 150, 80, 70, 110, 130],
                type: 'bar'
            }
        ]
    });
    myChart2.setOption({
        // title: {
        //     text: 'ECharts 入门示例'
        // },
        tooltip: {},
        legend: {
            data: ['销量']
        },
        xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
            {
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }
        ]
    });
}
</script>
   
<style scoped>
.charts {
    width: 100%;
    height: calc(100vh - 60px);
    display: flex;
    flex-wrap: wrap;
}

.bar {
    width: 100%;
    height: 49%;
}
</style>